<div class="Item hr">
    <div class="current">添加自定义表单</div>
    <div class="fr"><a href="{:U('index')}" class="btn">返回自定义表单列表</a></div>
</div>
<form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table1">
        <tr>
            <th width="150">自定义表单名称：</th>
            <td><input id="formname" type="text" class="input" size="20" name="diy[formname]" value="{$formname}" /> 
            <span onclick="ShowHide('help_formname')" class="icon-question-sign hand" title="帮助"></span> <span id="help_formname">（自定义表单的中文名称，在后台管理，前台发布等均使用此名字。）</span>
</td>
        </tr>
        <tr>
            <th>数据表：</th>
            <td><input id="formtable" type="text" class="input" size="20" name="diy[formtable]" disabled="disabled" value="{$formtable}" />
            <span onclick="ShowHide('help_formtable')" class="icon-question-sign hand" title="帮助"></span> <span id="help_formtable">（必须由英文、数字、下划线组成，用于保存自定义表单数据，不需要填写表前缀，不能和已有表名重复，创建后不可修改表名。）</span>
</td>
        </tr>
        <tr>
            <th>字段配置：</th>
            <td><a href="{:U('addfield', array('id' => $id))}" class="btn">添加字段</a></td>
        </tr>
        <tr>
            <td colspan="2">
                <table width="90%" border="0" cellspacing="0" cellpadding="0" class="tab">
                    <thead>
                        <tr>
                            <td>表单提示文字</td>
                            <td>数据字段名</td>
                            <td>数据类型</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody>
                        <volist name="fields" id="field">
                        <tr align="center">
                            <td>{$field.comment}</td>
                            <td>{$field.name}</td>
                            <td>{$fieldtype[$field['type']]}</td>
                            <td> <a href="{:U('editfield', array('id' => $id, 'fieldname' => $field['name']))}" class="icon icon-black icon-edit" title="编辑"></a> <a href="javascript:;" class="deleted icon icon-black icon-trash" data-url="{:U('doField')}" data-id="{$id}" data-fieldname="{$field.name}" data-title="{$field.comment}" title="删除"></a> </td>
                        </tr>
                        </volist>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr>
            <th>前台列表和内容页公开？：</th>
            <td>
                <label><input type="radio" value="2" name="diy[public]" {$public == 2 ? 'checked' : ''}>完全公开</label>
                <label><input type="radio" value="1" name="diy[public]" {$public == 1 ? 'checked' : ''}>公开审核过的</label>
                <label><input type="radio" value="0" name="diy[public]" {$public == 0 ? 'checked' : ''}>不公开</label>
            </td>
        </tr>
    </table>
    <input type="hidden" name="diy[id]" value="{$id}" />
</form>
<div class="commonBtnArea" >
    <button class="btn submit">提交</button>
</div>

<include file="DiyForm/javascript" />
<script type="text/javascript">
$(function(){
    submitForm("update");
    $(".deleted").click(function(){
        var url = $(this).data("url");
        var id = $(this).data("id");
        var name = $(this).data("title");
        var fieldname = $(this).data("fieldname");

        popup.confirm("您确定删除 <b>" + name + "</b> 字段？", '温馨提示',function(action){
            if(action == 'ok'){
                $.ajax({
					'url' : url,
					'dataType' : 'JSON',
					'type' : 'POST',
					'data' : {'id' : id, 'act' : 'delete', 'fieldname' : fieldname},
					'success' : function(json){
						if (json.status) {
							popup.success(json.info, "删除成功", function(){
								if(json.url){
									window.location.href = json.url;
								}else{
									top.window.location.reload();
								}
							});
						} else {
							popup.error(json.info);
							setTimeout(function(){
								popup.close("asyncbox_error");
							},2000);
						}
					}
				});
            }
        });

        return false;
    });
});
</script>
